package com.smart.mac.controller;

import com.smart.mac.common.R;
import com.smart.mac.model.dto.FlowTaskDTO;
import com.smart.mac.service.FlowInstanceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 流程实例
 *
 * @Author mac
 */
@RestController
@RequestMapping("/flowable/instance")
public class FlowInstanceController {

    @Autowired
    private FlowInstanceService flowInstanceService;


    /**
    * 结束流程实例(流程已有任务审核完成，不可终止)
     * 场景：开启流程人，不想走审批了，可以这样操作
    * @param: [flowTaskVo]
    * @return: com.elephant.demo.common.R
    * @author mac
    */
    @PostMapping(value = "/stopProcessInstance")
    public R stopProcessInstance(@RequestBody FlowTaskDTO flowTaskDTO) {
        flowInstanceService.stopProcessInstance(flowTaskDTO);
        return R.ok("结束流程成功");
    }


    /**
    * 激活或挂起流程实例
    * @param: [state 1:激活,2:挂起, instanceId 流程实例ID]
    * @return: com.elephant.demo.common.R
    * @author mac
    */
    @PostMapping(value = "/updateState")
    public R updateState(@RequestParam Integer state,@RequestParam String instanceId) {
        flowInstanceService.updateState(state,instanceId);
        return R.ok("激活或挂起流程成功");
    }
    
}
